<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon.ico">
  <link rel="mask-icon" href="/images/favicon.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"yoursite.com","root":"/","scheme":"Mist","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"always","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="网络基础笔记">
<meta property="og:type" content="article">
<meta property="og:title" content="网络相关">
<meta property="og:url" content="http://yoursite.com/2018/12/28/basic-2018-12-28-Network/index.html">
<meta property="og:site_name" content="Akiyama&#39;s Blog">
<meta property="og:description" content="网络基础笔记">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://yoursite.com/images/Network/%E5%8D%95%E6%92%AD.jpg">
<meta property="og:image" content="http://yoursite.com/images/Network/%E5%B9%BF%E6%92%AD.jpg">
<meta property="og:image" content="http://yoursite.com/images/Network/%E5%A4%9A%E6%92%AD.jpg">
<meta property="article:published_time" content="2018-12-27T16:00:00.000Z">
<meta property="article:modified_time" content="2019-03-12T19:55:01.586Z">
<meta property="article:author" content="丘山月夜">
<meta property="article:tag" content="网络">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://yoursite.com/images/Network/%E5%8D%95%E6%92%AD.jpg">

<link rel="canonical" href="http://yoursite.com/2018/12/28/basic-2018-12-28-Network/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>网络相关 | Akiyama's Blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">Akiyama's Blog</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">丘山月夜的博客</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="home fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="user fa fa-user fa-fw"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="tags fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="th fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="archive fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2018/12/28/basic-2018-12-28-Network/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="丘山月夜">
      <meta itemprop="description" content="君は空を見てるか,<br>風の音を聞いてるか">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Akiyama's Blog">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          网络相关
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-28 00:00:00" itemprop="dateCreated datePublished" datetime="2018-12-28T00:00:00+08:00">2018-12-28</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="far fa-calendar-check"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2019-03-13 03:55:01" itemprop="dateModified" datetime="2019-03-13T03:55:01+08:00">2019-03-13</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/" itemprop="url" rel="index"><span itemprop="name"></span></a>
                </span>
            </span>

          
            <div class="post-description">网络基础笔记</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h1 id="1-IP地址"><a href="#1-IP地址" class="headerlink" title="1. IP地址"></a>1. IP地址</h1><h2 id="1-1-分类"><a href="#1-1-分类" class="headerlink" title="1.1. 分类"></a>1.1. 分类</h2><h2 id="1-2-单播、广播、组播（多播）【转】"><a href="#1-2-单播、广播、组播（多播）【转】" class="headerlink" title="1.2. 单播、广播、组播（多播）【转】"></a>1.2. 单播、广播、组播（多播）【转】</h2><p>摘自<a target="_blank" rel="noopener" href="https://www.cnblogs.com/therock/articles/2798653.html">单播、广播和多播IP地址</a></p>
<h3 id="1-2-1-单播（一对一）"><a href="#1-2-1-单播（一对一）" class="headerlink" title="1.2.1. 单播（一对一）"></a>1.2.1. 单播（一对一）</h3><p>单播地址是IP网络中最常见的。包含单播目标地址的分组发送给特定主机。源地址-&gt;目标地址</p>
<ul>
<li>以太网帧报头中必须有目标IP地址和目标MAC地址。（目标IP地址+目标MAC地址）</li>
<li>如果目标地址属于另一个网络，则目标MAC地址为源地址所在网络的路由器的MAC地址。（目标IP地址+源地址的路由器MAC地址）</li>
</ul>
<p><img src="/images/Network/%E5%8D%95%E6%92%AD.jpg" alt="单播"></p>
<h2 id="1-2-2-广播（一对所有）"><a href="#1-2-2-广播（一对所有）" class="headerlink" title="1.2.2. 广播（一对所有）"></a>1.2.2. 广播（一对所有）</h2><p>广播分组的目标IP地址的主机部分全为1，这意味着本地网络（广播域）中的所有主机都将接收并查看该分组。</p>
<ul>
<li>以太网帧报头中必须有目标IP地址和广播MAC地址。（目标IP地址+广播MAC地址）</li>
<li>在以太网中，广播MAC地址长48位，其十六进制表示为FF-FF-FF-FF-FF-FF。</li>
</ul>
<p><img src="/images/Network/%E5%B9%BF%E6%92%AD.jpg" alt="广播"></p>
<h4 id="受限广播"><a href="#受限广播" class="headerlink" title="受限广播"></a>受限广播</h4><p>它不被路由发送，但会被送到相同物理网络段上的所有主机（不通过路由发送）</p>
<p>IP地址的网络字段和主机字段全为1，即地址：<strong>255.255.255.255</strong></p>
<h4 id="直接广播"><a href="#直接广播" class="headerlink" title="直接广播"></a>直接广播</h4><p>通过路由发送到该网络下的每台主机</p>
<p>IP地址的网络字段定义这个网络，主机字段通常全为1，如 192.168.10.255</p>
<h3 id="1-2-3-多播（一对多）"><a href="#1-2-3-多播（一对多）" class="headerlink" title="1.2.3. 多播（一对多）"></a>1.2.3. 多播（一对多）</h3><p>让源设备能够将分组发送给一组设备。属于多播组的设备将被分配一个多播组IP地址，多播地址范围为224.0.0.0～239.255.255.255。由于多播地址表示一组设备（有时被称为主机组），因此只能用作分组的目标地址。源地址总是为单播地址。</p>
<ul>
<li>以太网帧报头中必须有目标IP地址和多播MAC地址。</li>
<li>多播MAC地址以十六进制值01-00-5E打头，余下的6个十六进制位是根据IP多播组地址的最后23位转换得到的。</li>
</ul>
<p><img src="/images/Network/%E5%A4%9A%E6%92%AD.jpg" alt="多播"></p>
<h2 id="1-3-计算"><a href="#1-3-计算" class="headerlink" title="1.3. 计算"></a>1.3. 计算</h2><p>以下全部转换为2进制计算，判断是否属于同一个网段，主要看他们的网络标识是否一样</p>
<ul>
<li>网络标识（网络号）：子网掩码和IP地址进行”与”操作。用于区分不同的网段</li>
<li>主机标识（主机号）：子网掩码取反和IP地址进行“与”操作，用于区分同一网段下的不同主机</li>
<li>广播地址：主机段全为1的IP地址</li>
<li>最大主机数：2^主机段位数</li>
<li>可用主机数量：最大主机数-2（减去头和尾，第一个主机号表示本机，最后一个主机号表示广播地址）</li>
<li>子网数量：256/最大主机数</li>
<li>可用IP地址段：将网络地址下的所有主机分段，段数为子网数量，去掉头和尾，即为可用IP地址段</li>
</ul>
<p>子网掩码：转换为2进制，为1的部分对应网络段，为0的部分对应主机段</p>
<p>表示：IP地址（子网掩码）、IP地址/子网掩码</p>
<p>正常C网：子网掩码是255.255.255.0，也就是说前三段为网络号，最后一段为主机号。</p>
<p>如IP地址192.168.1.53：</p>
<blockquote>
<ul>
<li>网络标识为192.168.1</li>
<li>主机标识为53</li>
<li>子网数量为1</li>
<li>可用IP地址段为192.168.1.1-192.168.1.254</li>
<li>广播地址为192.168.1.255，主机号全为1：11111111，即255</li>
<li>最大主机数为256</li>
<li>可用主机数位254</li>
</ul>
</blockquote>
<p>如IP地址192.168.1.53/27</p>
<blockquote>
<ol>
<li>27表示子网掩码有27个1，即：11111111 11111111 11111111 11100000。即子网掩码为255.255.255.224。</li>
<li>网络段有27位，主机段有5位，得一个子网最大主机数为32，可用主机数位30，子网数量为8。</li>
<li>IP地址转换为二进制：11000000 10101000 00000001 00110101</li>
<li>和子网掩码进行与操作，得：11000000 10101000 00000001 00100000，即网络地址192.168.1.32。</li>
<li>和子网掩码取反后进行与操作，得：00000000 00000000 00000000 00010101，即主机标识为21，表示这个子网下的第21台主机</li>
<li>主机段全部置为1，得：11000000 10101000 00000001 00111111，即广播地址192.168.1.63</li>
<li>将网络分为8段：<ol>
<li>第一个子网：192.168.1.0-192.168.1.31</li>
<li>第二个子网：192.168.1.32-192.168.1.63</li>
<li>第三个子网：192.168.1.64-192.168.1.95</li>
<li>第四个子网：192.168.1.96-192.168.1.127</li>
<li>……</li>
</ol>
</li>
<li>53位于第二个子网，该子网的广播地址为192.168.1.63</li>
<li>该子网可用IP段为：192.168.1.33-192.168.1.62</li>
</ol>
</blockquote>

    </div>

    
    
    
        

  <div class="followme">
    <p>欢迎关注我的其它发布渠道</p>

    <div class="social-list">

        <div class="social-item">
          <a target="_blank" class="social-link" href="/images/wechat_channel.jpg">
            <span class="icon">
              <i class="fab fa-weixin"></i>
            </span>

            <span class="label">WeChat</span>
          </a>
        </div>
    </div>
  </div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/" rel="tag"><i class="fa fa-tag"></i> </a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/12/21/java-2018-12-21-JavaBasic/" rel="prev" title="java基础笔记（占坑）">
      <i class="fa fa-chevron-left"></i> java基础笔记（占坑）
    </a></div>
      <div class="post-nav-item">
    <a href="/2019/01/01/android-2019-1-1-ReactNative/" rel="next" title="ReactNative学习">
      ReactNative学习 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="header-overlay"></div>
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#1-IP%E5%9C%B0%E5%9D%80"><span class="nav-number">1.</span> <span class="nav-text">1. IP地址</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-1-%E5%88%86%E7%B1%BB"><span class="nav-number">1.1.</span> <span class="nav-text">1.1. 分类</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-%E5%8D%95%E6%92%AD%E3%80%81%E5%B9%BF%E6%92%AD%E3%80%81%E7%BB%84%E6%92%AD%EF%BC%88%E5%A4%9A%E6%92%AD%EF%BC%89%E3%80%90%E8%BD%AC%E3%80%91"><span class="nav-number">1.2.</span> <span class="nav-text">1.2. 单播、广播、组播（多播）【转】</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-1-%E5%8D%95%E6%92%AD%EF%BC%88%E4%B8%80%E5%AF%B9%E4%B8%80%EF%BC%89"><span class="nav-number">1.2.1.</span> <span class="nav-text">1.2.1. 单播（一对一）</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-2-2-%E5%B9%BF%E6%92%AD%EF%BC%88%E4%B8%80%E5%AF%B9%E6%89%80%E6%9C%89%EF%BC%89"><span class="nav-number">1.3.</span> <span class="nav-text">1.2.2. 广播（一对所有）</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%8F%97%E9%99%90%E5%B9%BF%E6%92%AD"><span class="nav-number">1.3.0.1.</span> <span class="nav-text">受限广播</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E7%9B%B4%E6%8E%A5%E5%B9%BF%E6%92%AD"><span class="nav-number">1.3.0.2.</span> <span class="nav-text">直接广播</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#1-2-3-%E5%A4%9A%E6%92%AD%EF%BC%88%E4%B8%80%E5%AF%B9%E5%A4%9A%EF%BC%89"><span class="nav-number">1.3.1.</span> <span class="nav-text">1.2.3. 多播（一对多）</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#1-3-%E8%AE%A1%E7%AE%97"><span class="nav-number">1.4.</span> <span class="nav-text">1.3. 计算</span></a></li></ol></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="丘山月夜"
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name">丘山月夜</p>
  <div class="site-description" itemprop="description">君は空を見てるか,<br>風の音を聞いてるか</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">60</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">21</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">丘山月夜</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://mist.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Mist</a> 强力驱动
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/muse.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

</body>
</html>
